import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
import { memberCartCount } from '@/api/cart'
import { useUserStore } from '@/stores'
export const useHeadGoodsStore = defineStore('head', () => {
  const store = useUserStore()
  const headGoods = ref([])
  const cartCount = ref(0)

  const setHeadGoods = data => {
    headGoods.value = data
  }

  const getCartCount = async () => {
    const res = await memberCartCount()
    cartCount.value = res.data.result.count
  }
  watch(
    () => store.isLogined,
    () => {
      getCartCount()
    }
  )

  return { headGoods, cartCount, setHeadGoods, getCartCount }
})
